package Function;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.*;

import FCRendering.FCRMaster;
import VWorldGameStudio.FCDate;
import VWorldGameStudio.FCPlayerInfo;
import VWorldGameStudio.FCSave;
import utils.FCDataSingles;

public class FCSaveLibrary {
	private ArrayList<String> savelist = new ArrayList<String>();
	private ArrayList<String> times = new ArrayList<String>();
	private Vector<String> filename = new Vector<>();
	private Vector<String> hostIds = new Vector<>();
	public FCSaveLibrary() {
		File ff= new File("./save");
		if(!ff.exists())ff.mkdir();
		File[] f =ff.listFiles();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
		for (int i = 0; i < f.length; i++) {
			String[] qw = FCDataSingles.getFileNameDE().filenameDecrypt(f[i].getName().replaceAll(".vw", ""))
					.split("-");
			long lastModify = f[i].lastModified();
			times.add(qw[0]);
			savelist.add("昵称:" + qw[1] + " 时间:" + simpleDateFormat.format(new Date(lastModify)));
			filename.add(f[i].getName().replaceAll(".vw", ""));
			hostIds.add(qw[0]);
		}
	}


	public ArrayList<String> getSaveTimelist() {
		return times;
	}

	public String getSaveInfoOfTime(String t) {
		return savelist.get(times.indexOf(t));
	}

	public int getSaveNum() {
		return savelist.size();
	} 

	public boolean unloadsaveinfo(FCPlayerInfo player1,
			FCSave gamesave, FCDate gamedate, FCTankLibrary tankl, int selectnum) {
		try {
			return FCDataSingles.getReader().readSaveData(player1,  gamesave, gamedate, tankl,
					"./save/" + filename.get(selectnum) + ".vw");
		} catch (Exception e) {
			return false;
		}
	}

	public void preInit(int selectnum){
		//设置hostId
		FCRMaster.gameSave.HOST_UID = hostIds.get(selectnum);
	}
}
